export default {
	data() {
		return {
			resLists: [],
			pageInfoObj: {
				page_size: 20,
				page: 1,
				count: -1,
			},
			pageloading: true,
			isShowPageLoadedTxt: false,
		}
	},

	async onLoad(option) {
		if(option && option.index >= '1') return; // 发货列表
		
		if(!['newerSence', 'diyBoxSence', 'competitionSence'].includes(option.fromlink)) {
			await this.resListsGetFun();
		}
	},
	async onReachBottom() {
		if(this.pageloading) {
			await (this.pageloading = false);
			await this.resListsGetFun();
			await (this.pageloading = true);
		}

	},
	methods: {
		async scrolltolower() {
			if(this.pageloading) {
				await (this.pageloading = false);
				await this.resListsGetFun();
				await (this.pageloading = true);
			}
		},
		pagingInitFun(page_size = 20) {
			this.resLists = [];
			this.pageInfoObj.page = 1;
			this.pageInfoObj.count = -1;
			this.pageInfoObj.page_size = page_size;
		},
		pagingAddFun() {
			this.pageInfoObj.page++;
		},
		pagingCountFun(count) {
			this.pageInfoObj.count = count;
		},
		pagingListFun(resLists) {
			this.resLists = [...this.resLists, ...resLists];
		},
		pagingMoreFun() {
			const {pageInfoObj, resLists} = this;
			if (pageInfoObj.count !== -1 && pageInfoObj.count <= resLists.length) {
				this.isShowPageLoadedTxt = true;
				return false;
			}else{
				this.isShowPageLoadedTxt = false;
				return true;
			}
		},
		async resListsGetFun() {
			if(!this.pagingMoreFun()){
				return;
			}
			const result = await this.listsGetFun();
			if(!result) return;
			const { resLists, count } = result;
			await this.pagingListFun([...resLists]);
			await this.pagingCountFun(count);
			await this.pagingAddFun();
			await this.pagingMoreFun();
		},
	},

}